package z;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ch6_1 implements ActionListener {
    JFrame frame;
    JLabel l1,l2,l3;
    JTextField t;
    JPasswordField pass;
    JButton b1,b2;
    JPanel pane;
    public ch6_1() {
        frame = new JFrame();
        l1 = new JLabel("请输入用户名与密码：");
        l2 =new JLabel("用户名");
        l3 = new JLabel("密码");
        t = new JTextField(10);
        pass = new JPasswordField(10);
        b1 = new JButton("登录");
        b2 = new JButton("重置");
        pane = new JPanel();
        pane.add(l1);
        pane.add(l2);
        pane.add(l3);
        pane.add(t);
        pane.add(pass);
        pane.add(b1);
        pane.add(b2);
        pane.setLayout(null);
        l1.setBounds(30, 10, 200, 20);
        l2.setBounds(10, 40, 80, 20);
        l3.setBounds(10, 90, 100, 20);
        t.setBounds(10, 100, 100, 20);
        pass.setBounds(10, 140, 100, 20);
        b1.setBounds(10, 160, 100, 20);
        b2.setBounds(10, 180, 100, 20);
        frame.add(pane);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setSize(300,300);
        b1.addActionListener(this);
        b2.addActionListener(this);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == b1) {
            if(t.getText().equals("admin")&&pass.getPassword().equals("123456")){
                JOptionPane.showMessageDialog(this,"登陆成功");
            }else{
                JOptionPane.showMessageDialog(this,"登陆不成功");
            }
        }
        if (e.getSource() == b2) {
            t.setText("");
            pass.setText("");
        }
    }
}
